#pragma once
#include <stdint.h>
#ifdef _WINDOWS

#ifdef _DLLEXPORT
#define WINEXPORT __declspec(dllexport)
#else
#define WINEXPORT __declspec(dllimport)
#endif

#define EXPORT
#else
#define EXPORT __attribute__ ((visibility("default")))
#define WINEXPORT
#endif
enum ERROR_CODE{
    STATUS_SUCCESS,
    STATUS_ERROR,
    STATUS_SOCKET_FAILED,           
    STATUS_SOCKET_CONNECT_FAILED,   
    STATUS_SOCKET_SEND_FAILED,      
};



/**
 * @brief 
 *      Image type
 */
enum IMG_TYPE{
    IMG_DEPTH,
    IMG_AMPLITUDE,
    IMG_RGB,
};

/**
 * @brief 
 *      Image data.
 */
struct STRC_IMG{
    IMG_TYPE type;
    int len;
    uint16_t *data;
};

struct STRC_IMG_ALL{
    STRC_IMG img_rgb;
    STRC_IMG img_amplitude;
    STRC_IMG img_depth;
};

extern "C" {
    /**
     * @brief
     *      SDK initialization
     */
    WINEXPORT void api_init();

    /**
     * @brief
     *      exit SDK
     */
    WINEXPORT void api_exit();


    /**
     * @brief
     *      Connect to device.
     * @param ip
     *      IP of the device.
     * @param port
     *      Port of the device.
     * @return int
     *      <0  failed
     *      >=0 success,The handle of the device.
     */
    WINEXPORT int api_connect(char* ip, int port = 65300);

    /**
     * @brief
     *      Disconnect from the device.
     * @param handle
     *      The handle of the device.
     * @return int
     *      >=0     success
     *      <0      failed
     */
    WINEXPORT int api_disconnect(int handle);


    /**
     * @brief
     *      Get the version of the SDK
     * @return char*
     *      The version of the SDK
     */
    WINEXPORT char* api_get_sdk_ver();

    /**
     * @brief
     *      Get the version of the device.
     * @param handle
     *      The handle of the device.
     * @return char*
     *      ==NULL  failed
     *      !=NULL  the version of the device
     */
    WINEXPORT char* api_get_dev_ver(int handle);
    /**
     * @brief
     *      Get the camera intrinsic parameters.
     * @param handle
     *      The handle of the device.
     * @return char*
     *      ==NULL  failed
     *      !=NULL  The camera intrinsic parameters.
     */
    WINEXPORT char* api_get_intrinsic_parameters(int handle);
    /**
     * @brief
     *      Get image.
     * @param handle
     *      The handle of the device.
     * @return STRC_IMG_ALL*
     *      ==NULL     No data.
     *      !=NULL     Data of the image.
     *
     */
    WINEXPORT STRC_IMG_ALL* api_get_img(int handle);

    /**
     * @brief
     *      Get the last error code.
     * @return ERROR_CODE
     */
    WINEXPORT ERROR_CODE api_errorcode();

    /**
     * @brief 
     *      Gets the current camera exposure level
     * @param handle 
     *      The handle of the device.
     * @param min
     *      Minimum exposure level returned
     * @param max
     *      Maximum exposure level returned
     * @return int 
     *      >=0 The current exposure level
     *      <0  failed
     *      ==-1    Initialization incomplete
     *      
     */
    WINEXPORT int api_get_exposure(int handle , int *min , int *max);

    /**
     * @brief 
     *      Set exposure level.
     * @param handle 
     *      The handle of the device.
     * @param exposure 
     *      exposure level
     * @return int 
     *      >=0 success
     *      <0  failed
     */
    WINEXPORT int api_set_exposure(int handle , int exposure);
};
